package com.libre.view.file;

import javafx.beans.InvalidationListener;
import javafx.beans.property.ReadOnlyIntegerWrapper;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.Event;
import javafx.geometry.Side;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebView;
import javafx.stage.Stage;


public class ShowView extends Stage {

    public ShowView(){
        BorderPane pane = new BorderPane();
        // 选项卡
        TabPane tabPane = new TabPane();
        //设置关闭按钮显示模式
        tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
        //设置Tab方位
        tabPane.setSide(Side.TOP);
        Tab sealTab = new Tab("印章");
        tabPane.getSelectionModel().select(sealTab);  //默认选中
        Tab qrTab = new Tab("条码");
        Tab watermarkTab = new Tab("水印");
        tabPane.getTabs().add(sealTab);
        tabPane.getTabs().add(qrTab);
        tabPane.getTabs().add(watermarkTab);

        final GridPane[] gridPane = {new SealTab().getGridPane()};//默认
        VBox vBox = new VBox();
        vBox.getChildren().addAll(tabPane, gridPane[0]);
        pane.setLeft(vBox);
        tabPane.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {
            @Override
            public void changed(ObservableValue observable, Object oldValue, Object newValue) {
                if (newValue == sealTab) {
                    gridPane[0] = new SealTab().getGridPane();
                    VBox vBox = new VBox();
                    vBox.getChildren().addAll(tabPane, gridPane[0]);
                    pane.setLeft(vBox);
                } else if (newValue == qrTab) {
                    gridPane[0] = new QrTab().getGridPane();
                    VBox vBox = new VBox();
                    vBox.getChildren().addAll(tabPane, gridPane[0]);
                    pane.setLeft(vBox);
                } else if (newValue == watermarkTab) {
                    gridPane[0] = new WatermarkTab().getGridPane();
                    VBox vBox = new VBox();
                    vBox.getChildren().addAll(tabPane, gridPane[0]);
                    pane.setLeft(vBox);
                }
            }
        });

        WebView webView = new WebView();
        webView.getEngine().load("https://www.baidu.com");

        pane.setCenter(webView);
        Stage stage = new Stage();
        Scene scene = new Scene(pane);
        scene.getStylesheets().add("./static/css/common.css");
        stage.setScene(scene);
        stage.setMaximized(true);//全屏
        stage.show();
    }

}
